import { http } from '@/api/service/request';

export interface GraphNodeDTO {
  id: string;
  label: string;
  type: string;
  description?: string;
  color?: string;
  size?: number;
}

export interface GraphEdgeDTO {
  source: string;
  target: string;
  type: string;
  name: string;
}

export interface GraphDTO {
  nodes: GraphNodeDTO[];
  edges: GraphEdgeDTO[];
}


/** 获取所有课程和前置课程关系，用于图的初始化 */
export const getCoursesInitGraph = () => {
  return http.request<GraphDTO>('get', '/graph/courses-init');
};

/** 获取节点及其一度邻居 */
export const getNodeWithNeighbors = (nodeId: string) => {
  return http.request<GraphDTO>('get', `/graph/node/${nodeId}`);
};

/** 获取所有节点类型 */
export const getAllNodeTypes = () => {
  return http.request<string[]>('get', '/graph/node-types');
};

/** 根据类型和关键词搜索子图 */
export const searchSubgraph = (type: string, keyword: string) => {
  return http.request<GraphDTO>('get', '/graph/subgraph', {
    params: { type, keyword }
  });
};

/** 获取节点属性详情 */
export const getNodeProperties = (nodeId: string) => {
  return http.request<Record<string, any>>('get', `/graph/node/${nodeId}/properties`);
};
